﻿using System.Data.Entity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ninject;
using SDM.ExamPlanner.BLL;
using SDM.ExamPlanner.BLL.Interfaces;
using SDM.ExamPlanner.DALC;
using SDM.ExamPlanner.DALC.Interfaces;
using SDM.ExamPlanner.DTO;

namespace SDM.ExamPlanner.Test
{
    [TestClass]
    public class BaseTest
    {
        [TestInitialize]
        public void Initialize()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<DataContext>());
            
            Ninjector.Kernel.Bind<DataContext>().ToConstant(new DataContext(@"Data Source=.\SQLEXPRESS;Initial Catalog=SDM.ExamPlanner.Test;Integrated Security=SSPI;"));
            Ninjector.Kernel.Bind(typeof (IRepository<>)).To(typeof (DataRepository<>));
            Ninjector.Kernel.Bind(typeof (IManager<>)).To(typeof (Manager<>));
        }

        [TestCleanup]
        public void CleanUp()
        {
            var context = Ninjector.Kernel.Get<DataContext>();
            new DropCreateDatabaseAlways<DataContext>().InitializeDatabase(context);
            
            Ninjector.Kernel.Unbind<DataContext>();
            Ninjector.Kernel.Unbind(typeof(IRepository<>));
            Ninjector.Kernel.Unbind(typeof(IManager<>));
        }
    }
}
